#include <iostream>

#include "aerial\IFCS.h"

using namespace std;

#include "hge\hge.h"
#include "hge\hgesprite.h"
#include "hge\hgeresource.h"
#include "hge\hgevector.h"
#include "hge\hgefont.h"

#include "vulcan.h"

HGE* hge;
hgeFont* fnt;
hgeResourceManager hrm;
Vulcan* vulcan;

IFCS ifcs;

bool FrameFunc()
{
	static bool lstatus = false;
	float dt = hge->Timer_GetDelta();
	float ctime = hge->Timer_GetTime();

	hgeVector a;
	float dx, dy;
	bool c;
	if ((c = hge->Input_GetKeyState(HGEK_LBUTTON)) ^ lstatus)
	{
		if (!lstatus)
		{
			hgeVector d;
			hge->Input_GetMousePos(&dx, &dy);
			d.x = dx - 400.f;
			d.y = dy - 300.f;
			d.Normalize();
			vulcan = new Vulcan(&hrm, 400.f, 300.f, d.x, d.y, ctime, 0); 
			ifcs.addWeapon(vulcan);
		} else {
			if (vulcan ) {
				ifcs.removeWeapon(vulcan);
			} else {
				cout << "wrong";
			}
		}
	}
	lstatus = c;
	ifcs.Update(dt);
	return false;
}

bool RenderFunc()
{
	hge->Gfx_BeginScene();
	hge->Gfx_Clear(0);
	fnt->printf(5, 5, HGETEXT_LEFT, "dt: %f", hge->Timer_GetDelta());
	fnt->printf(5, 55, HGETEXT_LEFT, "Weapon Alive: %d", ifcs.getWeaponAlive());
	ifcs.Render();
	hge->Gfx_EndScene();
	return false;
}

int main()
{
	hge = hgeCreate(HGE_VERSION);

	hge->System_SetState(HGE_LOGFILE, "bulletTest.log");
	hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
	hge->System_SetState(HGE_RENDERFUNC, RenderFunc);
	hge->System_SetState(HGE_TITLE, "A.I.R barage");
	hge->System_SetState(HGE_WINDOWED, true);
	hge->System_SetState(HGE_SCREENWIDTH, 800);
	hge->System_SetState(HGE_SCREENHEIGHT, 600);
	hge->System_SetState(HGE_SCREENBPP, 32);
	hge->System_SetState(HGE_HIDEMOUSE, false);
	hge->System_SetState(HGE_SHOWSPLASH, false);
	hge->System_SetState(HGE_FPS, 60);

	if(hge->System_Initiate())
	{
		hrm.ChangeScript("aeria.res");
		hrm.Precache();
		fnt = hrm.GetFont("fnt.original");
		if (fnt) {
			hge->System_Start();
		}
		hrm.Purge();
	}
	hge->System_Shutdown();
	hge->Release();
	return 0;
}